﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Anticheat.Math.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var one = new SecureInteger(1);
            var one2 = new SecureInteger(1);
            SecureInteger two = 2;
            // equality
            Debug.Assert(one != two);
            Debug.Assert(one2 != two);
            Debug.Assert(one == one2);
            Debug.Assert(one + one2 == two);
            //validity
            Debug.Assert(one.IsValid);
            Debug.Assert(two.IsValid);
            SecureInteger four = two + two;
            int four2 = two * 2;
            SecureInteger four3 = 4;
            // calc
            Debug.Assert(four == four2);
            Debug.Assert(four > two);
            Debug.Assert(four > one);
            // let's interfere
            FieldInfo f = typeof(SecureInteger).GetField("Value1", BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo f2 = f.FieldType.GetField("value", BindingFlags.NonPublic | BindingFlags.Instance);
            object wrap1 = f.GetValue(four);
            f2.SetValue(wrap1, 5);
            //alarms fired!
            Debug.Assert(!four.IsValid);
            Debug.Assert(four != four2);
            Debug.Assert(four != four3);
            // ReSharper disable EqualExpressionComparison
            Debug.Assert(four == four); // reference equality
            // ReSharper restore EqualExpressionComparison
            Console.WriteLine("OK");
            Console.ReadLine();
        }
    }
}
